//
//  HomePageController.m
//  LearnObjectiveC
//
//  Created by 吴可高 on 16/5/5.
//  Copyright © 2016年 吴可高. All rights reserved.

#import "HomePageController.h"
#import "VisitorTest.h"
#import "StateTest.h"
#import "MementoTest.h"
#import "CommendTest.h"
#import "IteratorTest.h"
#import "StrategyTest.h"
#import "ProtocolStrategyTest.h"
#import "TemplateAbstractTest.h"
#import "AdapterTest.h"
#import "WrapperTest.h"
#import "InterfaceSourceTest.h"
#import "DecoraterTest.h"
#import "ProxyTest.h"
#import "ComputerOperation.h"
#import "BridgeTest.h"
#import "TreeTest.h"
#import "StateMachineModel.h"

#import "UnderlyingInvoke.h"
#import "UnderInherite.h"
#import "TestUnderObject.h"

@interface HomePageController()<SStateMachineModelDelegate>
@property(nonatomic,strong) StateMachineModel * stateMachineModel;

@end

@implementation HomePageController

-(void)viewDidLoad
{
    [super viewDidLoad];
    /*
    [[[VisitorTest alloc]init]staticVisitor];
    [[[StateTest alloc]init]startState];
    [[[MementoTest alloc]init]mementoStorage];
    [[[CommendTest alloc]init]commendInvoker];
    [[[IteratorTest alloc]init]iterator];
    [[[StrategyTest alloc]init]strategycalculate];
    [[ProtocolStrategyTest alloc]strategycalculate];
    [[[TemplateAbstractTest alloc]init]templateAbstractTest];
    [[[AdapterTest alloc]init]adapterTest];
    [[[WrapperTest alloc]init]wrapperTest];
    [[[InterfaceSourceTest alloc]init]interfaceSource];
    [[[DecoraterTest alloc]init]decorater];
    [[[ProxyTest alloc]init]proxy];
    [[[ComputerOperation alloc]init]computer];
    [[[BridgeTest alloc]init]bridge];
    [[[TreeTest alloc]init]treeNode];
    [self initializeStateMachine];
    */
    TestUnderObject * underObject = [[TestUnderObject alloc]init];
    underObject.testUnderName = @"testUnderName";
    underObject.testUnderIndefiner = @"testUnderIndefiner";
    underObject.inherite_classIndefiner = @"inherite_classIndefiner";
    underObject.inherite_name = @"inherite_name";
    underObject.invokeSelectorName = @"invokeSelectorName";
    
    NSData * data = [NSKeyedArchiver archivedDataWithRootObject:underObject];
    [[NSUserDefaults standardUserDefaults]setObject:data forKey:@"key"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSData * unarhiveData = [[NSUserDefaults standardUserDefaults]objectForKey:@"key"];
        id unarchiveObject = [NSKeyedUnarchiver unarchiveObjectWithData:unarhiveData];
        if ([unarchiveObject isKindOfClass:[UnderInherite class]]) {
            TestUnderObject * underObject = (TestUnderObject*)unarchiveObject;
            NSString * content = [NSString stringWithFormat:@"\ntestUnderName:%@\ntestUnderIndefiner:%@\nname:%@\nclassIndefiner:%@\ninvokeSelectorName:%@\n",underObject.testUnderName,underObject.testUnderIndefiner,underObject.inherite_name,underObject.inherite_classIndefiner,underObject.invokeSelectorName];
            NSLog(@"%@",content);
        }
    });
}

-(void)initializeStateMachine
{
    self.stateMachineModel = [[StateMachineModel alloc]init];
    self.stateMachineModel.delegate = self;
    [self.stateMachineModel performEventWithEventType:SSEventTypeInit];
}

-(void)stateMachineModel:(StateMachineModel*)stateMachineModel changeFromState:(SStateType)currentStateType to:(SStateType)nextStateType;
{
    NSLog(@"%ld-%ld",(SStateType)currentStateType,(SStateType)nextStateType);
    if (nextStateType == SSStateTypeCheckPayParameters) {
        [self.stateMachineModel performEventWithEventType:SSEventTypeCheckDeviceId];
    }
    if (nextStateType == SSEventTypeCheckDeviceId) {
        NSLog(@"整个状态机已经完成");
    }
}

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}

@end
